proc
	OutputLog(color, var/message as text)
		for(var/client/C) if(C.ckey in Admins)
			var/Time = C.getTime()
			C<<output("<b>\[</b>[Time]<b>\] <font color = \"#[color]\">[message]</font>","Admin_Log.log_output")
client/proc
	OutputUserLog(var/client/target, var/client/source, var/message)
		for(var/client/C) if(C.ckey in Admins)
			var/Time = C.getTime()
			C<<output("<b>\[</b>[Time]<b>\]</b> <b><font color='#[source.Name_Color]'>[source.name]</font></b> to <b><font color='#[target.Name_Color]'>[target.name]</font></b>: [message]","Admin_UserLog.userlog_output")

	Administrate(user, action)
		if(action == "Mute")
			if(user in MuteList || checkMute(user)) System_UserMessage(src,"[user] is already muted.")
			else
				System_WorldMessage("[user] has been muted by [src.key].")
				AddPunishment(src.key, user, "Mute")
				src.adminUpdateQuick()

		else if(action == "Ban")
			if(user in Banned || checkBan(user)) System_UserMessage(src,"[user] is already banned.")
			else
				System_WorldMessage("[user] has been banned by [src.key].")
				AddPunishment(src.key, user, "Ban")
				del(findTarget(user))
				src.adminUpdateQuick()

		else if(action == "Unmute")
			if(user in MuteList || checkMute(user))
				System_WorldMessage("[user] has been unmuted by [src.key].")
				AddPunishment(src.key, user, "Unmute")
				src.AdminUpdateForgive()
			else
				System_UserMessage(src,"[user] is not muted.")

		else if(action == "Unban")
			if(user in Banned || checkMute(user))
				System_WorldMessage("[user] has been unbanned by [src.key].")
				AddPunishment(src.key, user, "Unban")
				src.AdminUpdateForgive()
			else
				System_UserMessage(src,"[user] is not banned.")

		else if(action == "Kick")
			AddPunishment(src.key, user, "Kick")
			src.adminUpdateQuick()

		updateUsers()

	ChangeMod(var/client/C, var/status as text)
		if(status == "ON")
			if(!(C.ckey in Moderators))
				C.verbs+=typesof(/client/Mod/verb)
				C.Font_Weight = "bold"
		else if(status == "OFF")
			if(C.ckey in Moderators)
				C.verbs-=typesof(/client/Mod/verb)
				C.Font_Weight = "normal"
		updateUsers()


client/verb

	ListOP()
		set hidden = 1
		var/admins = "Admins: "
		var/mods = "Moderators: "
		var/count = 0
		for(var/a in Admins) count++
		for(var/a in Admins)
			count--; admins += a
			if(count > 0) admins += ", "

		count = 0
		for(var/a in Moderators) count++
		if(count > 0)
			for(var/a in Moderators)
				count--; mods += a
				if(count > 0) mods += ", "

		System_UserMessage(src, admins)
		System_UserMessage(src, mods)

client/Admin/verb

	Promote(var/person as text)
		set hidden = 1; if(!(ckey in Admins)) return
		OutputLog(GREEN,"[src.key] tried to make [person] a Mod.")
		person = ckey(person)
		if(person in Admins) return
		if(!(person in Moderators))
			var/client/C = findTarget(person)
			if(C) ChangeMod(C, "ON")
			System_WorldMessage("[src.key] has made [person] a Moderator.")
			Moderators+=person

	Demote(var/person as text)
		set hidden = 1; if(!(ckey in Admins)) return
		OutputLog(GREEN,"[src.key] tried to remove [person] as Mod.")
		person = ckey(person)
		if(person in Moderators)
			var/client/C = findTarget(person)
			if(C) ChangeMod(C, "OFF")
			System_WorldMessage("[src.key] has removed [person]'s Mod.")
			Moderators-=person

	Zero(var/key as text)
		set hidden = 1
		if(!(ckey in Admins)) return
		var/client/person = findTarget(key)
		if(person)
			person.Credits = 0
			person.SaveCasino()
			System_UserMessage(person,"Your credits have been taken due to some violation.")
			OutputLog(RED,"[src.key] has issued a zero balance to [person]")

	CleanSlate(var/key as text)
		set hidden = 1
		if(!(ckey in Admins)) return
		var/client/person = findTarget(key)
		if(person)
			person.Credits = 1000
			person.TotalSpins = 0
			person.TotalWager = 0
			person.TotalWon = 0
			person.SaveCasino()
			System_UserMessage(person,"You casino history has been cleared, and you have been granted 1000 credits to start new.")
			OutputLog(RED,"[src.key] has issued a clean slate to [person].")


	RebootButton()
		set hidden = 1
		if(!(ckey in Admins))
			return
		else
			var/timer = text2num(winget(src,"Admin_Settings.admin_inputtime","text"))
			if(timer == 0)
				Reboot = FALSE
				System_WorldMessage("[src.key] has canceled the reboot.")
			else
				if(Reboot == TRUE)
					RebootTimer = timer
					System_WorldMessage("[src.key] has changed the reboot time to [RebootTimer] seconds.")
				else
					Reboot = TRUE
					RebootTimer = timer
					System_WorldMessage("[src.key] has called for a reboot in [RebootTimer] seconds.")
					RebootWorld()

	CancelButton()
		set hidden = 1
		if(!(ckey in Admins)) return
		Reboot = FALSE
		System_WorldMessage("[src.key] has canceled the reboot..")
		for(var/client/C)
			if(C.ckey in Admins)
				winset(C,"Admin_Settings.admin_ServerStatus","text=\"Server is currently running.\"")

	SetCharLimit(var/number as num|null)
		set hidden = 1
		if(!(ckey in Admins))
			return
		else
			var/newlimit
			if(number) newlimit = number
			else newlimit = text2num(winget(src,"Admin_Settings.admin_charlimit","text"))
			if(newlimit == LengthLimit) return
			else
				if(newlimit == null) newlimit = 0
				LengthLimit = newlimit
				System_WorldMessage("[src] has set the character limit to [LengthLimit].")
/*
	SetTopic()
		set hidden = 1
		if(!(ckey in Admins))
			return
		else
			var/newtopic = winget(src,"Admin_Settings.admin_topic","text")
			if(newtopic == ConversationTopic) return
			else
				ConversationTopic = newtopic
				for(var/client/M) M<<output("<div style=\"position: absolute; top: 0px; left: 5px; width:100%;\">[ConversationTopic]</div>","Main.Topic")
				System_WorldMessage("[src] has changed the topic.")
				OutputLog(GREEN,"[src] has changed the topic.")
*/
	SetTopic()
		set hidden = 1
		if(!(ckey in Admins))
			return
		else
			var/newtopic = winget(src,"Admin_Settings.admin_topic","text")
			if(newtopic == ConversationTopic) return
			else
				ConversationTopic = newtopic
				for(var/client/M)
					M<<output(null,"Main.Topic")
					M<<output("[ConversationTopic]","Main.Topic")
					winset(M,"Main.Topic","style=position:absolute;top:0px;")
				System_WorldMessage("[src] has changed the topic.")
				OutputLog(GREEN,"[src] has changed the topic.")

	Punish()
		set hidden = 1
		if(!(ckey in Admins))
			return
		else
			var/client/target = winget(src,"Admin_Settings.admin_userinput","text")
			if(!target)
				return
			else
				var/Punishment = "Ban"
				Administrate(target, Punishment)

client/Mod/verb

	Mute(var/target as text)
		set hidden = 1
		if(ckey in (Admins|Moderators))
			Administrate(target, "Mute")

	Voice(var/target as text)
		set hidden = 1
		if(ckey in (Admins|Moderators))
			Administrate(target, "Unmute")

	Ban(var/target as text)
		set hidden = 1
		if(ckey in (Admins|Moderators))
			Administrate(target, "Ban")

	Unban(var/target as text)
		set hidden = 1
		if(ckey in (Admins|Moderators))
			Administrate(target, "Unban")

	Kick(var/target as text)
		set hidden = 1
		if(ckey in (Admins|Moderators))
			Administrate(target, "Kick")
	Idle(var/time as num)
		set hidden = 1
		if(ckey in (Admins|Moderators))
			IdleTime = time
			System_WorldMessage("[src] has set the Idle Timer to [time] minutes.")

proc
	RebootWorld()
		while(RebootTimer>=0&&Reboot)
			RebootTimer--
			for(var/client/C)
				if(C.ckey in Admins)
					winset(C,"Admin_Settings.admin_ServerStatus","text=\"Server will reboot in [RebootTimer] seconds.\"")
			if(RebootTimer==60) System_WorldMessage("Reboot will occur in roughly [RebootTimer] seconds.")
			if(RebootTimer==30) System_WorldMessage("Reboot will occur in roughly [RebootTimer] seconds.")
			if(RebootTimer==5) System_WorldMessage("Reboot will occur in roughly [RebootTimer] seconds.")
			if(RebootTimer==0)
				System_WorldMessage("REBOOT (byond://[world.internet_address]:[world.port])")
				world.Reboot()
			sleep(10)


